<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
  <title>verify (Yubico)</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
  <pre><span class="ruby-comment cmt"># File yubico.rb, line 136</span>
                <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">verify</span>( <span class="ruby-identifier">otp</span>, <span class="ruby-identifier">id</span> = <span class="ruby-ivar">@_id</span> )
                  <span class="ruby-ivar">@_id</span> = <span class="ruby-identifier">id</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@_id</span>.<span class="ruby-identifier">nil?</span>
                        <span class="ruby-comment cmt"># Set up the full URL for the request, then pass it through the +URI+ gauntlet.</span>
                        <span class="ruby-identifier">fullurl</span> = <span class="ruby-value str">&quot;http://api.yubico.com/wsapi/verify?id=&quot;</span><span class="ruby-operator">+</span> (<span class="ruby-ivar">@_id</span>.<span class="ruby-identifier">to_s</span>) <span class="ruby-operator">+</span><span class="ruby-value str">&quot;&amp;otp=&quot;</span><span class="ruby-operator">+</span> <span class="ruby-identifier">otp</span>
                        <span class="ruby-identifier">url</span> = <span class="ruby-constant">URI</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">fullurl</span>)
                        <span class="ruby-comment cmt"># Make the call to the server and return the full response, not just the body (to be used later)</span>
                        <span class="ruby-identifier">res</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">start</span>(<span class="ruby-identifier">url</span>.<span class="ruby-identifier">host</span>, <span class="ruby-identifier">url</span>.<span class="ruby-identifier">port</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">http</span><span class="ruby-operator">|</span>
                          <span class="ruby-identifier">http</span>.<span class="ruby-identifier">get</span>((<span class="ruby-identifier">url</span>.<span class="ruby-identifier">path</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;?&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">url</span>.<span class="ruby-identifier">query</span>))
                        }
                  <span class="ruby-comment cmt"># Parse and find the status within the response's body, to verify this is, in fact, what we're looking for.</span>
                  <span class="ruby-keyword kw">if</span> ( <span class="ruby-operator">!</span>(<span class="ruby-regexp re">/status=([a-zA-Z0-9_]+)/</span>.<span class="ruby-identifier">match</span>(<span class="ruby-identifier">res</span>.<span class="ruby-identifier">body</span>)) )
                    <span class="ruby-comment cmt"># If it's not, let's raise an error.</span>
                    <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;Response Error: &quot;</span><span class="ruby-operator">+</span> <span class="ruby-identifier">res</span>.<span class="ruby-identifier">body</span>
              <span class="ruby-keyword kw">else</span> 
                <span class="ruby-ivar">@_res</span> = <span class="ruby-identifier">res</span>.<span class="ruby-identifier">body</span>
              <span class="ruby-keyword kw">end</span>
                  <span class="ruby-comment cmt"># Finally, return the response value.</span>
                  <span class="ruby-ivar">@_res</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp re">/status=([a-zA-Z0-9_]+)[\s]/</span>).<span class="ruby-identifier">first</span>.<span class="ruby-identifier">to_s</span>
                <span class="ruby-keyword kw">end</span></pre>
</body>
</html>